﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Text.RegularExpressions;

namespace SCOSub
{
    public partial class Process100ms : Form
    {
        public delegate void SetFormTopMostEventHandel(bool topmost);
        public event SetFormTopMostEventHandel SetFormTopMostEvent;

        public Process100ms()
        {
            InitializeComponent();
            this.TopMost = Const.DoTopMost;

        }

        private string rep(Match m)
        {
            int h = int.Parse(m.Groups[2].Captures[0].Value);
            int min = int.Parse(m.Groups[3].Captures[0].Value);
            int s = int.Parse(m.Groups[4].Captures[0].Value);
            int ms = int.Parse(m.Groups[5].Captures[0].Value);
            int allms = h * 3600 * 1000 + min * 60 * 1000 + s * 1000 + ms * 10;//得到毫秒
            if ((allms / 10) % 10 <= 6)//开始时间6一下舍，包括6
                allms = (int)(allms / 100) * 100;
            else allms = (int)(allms / 100) * 100 + 100;

            h = (int)(allms / 3600 / 1000);
            min = (int)((allms - h * 3600 * 1000) / 60 / 1000);
            s = (int)((allms - h * 3600 * 1000 - min * 60 * 1000) / 1000);
            ms = allms % 1000 / 10;
            string starttime = string.Format(@"{0:D1}:{1:D2}:{2:D2}.{3:D2}", h, min, s, ms);
            //---------
            h = int.Parse(m.Groups[6].Captures[0].Value);
            min = int.Parse(m.Groups[7].Captures[0].Value);
            s = int.Parse(m.Groups[8].Captures[0].Value);
            ms = int.Parse(m.Groups[9].Captures[0].Value);
            allms = h * 3600 * 1000 + min * 60 * 1000 + s * 1000 + ms * 10;//得到毫秒
            if ((allms / 10) % 10 <= 4)//结束时间5以上入
                allms = (int)(allms / 100) * 100;
            else allms = (int)(allms / 100) * 100 + 100;

            h = (int)(allms / 3600 / 1000);
            min = (int)((allms - h * 3600 * 1000) / 60 / 1000);
            s = (int)((allms - h * 3600 * 1000 - min * 60 * 1000) / 1000);
            ms = allms % 1000 / 10;
            string endtime = string.Format(@"{0:D1}:{1:D2}:{2:D2}.{3:D2}", h, min, s, ms);


            return string.Format(",Dialogue: {0},{1},{2},{3},{4},{5},{6},{7},{8}", m.Groups[1].Captures[0].Value, starttime, endtime, m.Groups[10].Captures[0].Value, m.Groups[11].Captures[0].Value, m.Groups[12].Captures[0].Value, m.Groups[13].Captures[0].Value, m.Groups[14].Captures[0].Value, m.Groups[15].Captures[0].Value);


        }

        private void richTextBox1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            richTextBox1.Text = Regex.Replace(richTextBox1.Text, @"Dialogue: ([0-9]+),([0-9]):([0-9]{2}):([0-9]{2}).([0-9]{2}),([0-9]):([0-9]{2}):([0-9]{2}).([0-9]{2}),([^,]+),([^,]*),([^,]*),([^,]*),([^,]*),([.]*)", rep, RegexOptions.IgnoreCase);
        }

        private void Process100ms_FormClosed(object sender, FormClosedEventArgs e)
        {
            SetFormTopMostEvent(true);
        }
    }
}
